package com.zxhtom.application;

import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import java.io.IOException;





public class QiNiuFileUpUtil
{
    String ACCESS_KEY = "koN2AnoftieF_BLsgFQ0PhXhgA_tU5YXb-k-VppV";
    String SECRET_KEY = "N1gJ3hDJ5xglHUigYrl8FG2rwFLA1qmXPAsuj8q6";

    String bucketname = "yanhuasanjin13141";








    Auth auth = Auth.create(this.ACCESS_KEY, this.SECRET_KEY);

    UploadManager uploadManager = new UploadManager(new Configuration());




    public String getUpToken() { return this.auth.uploadToken(this.bucketname); }








    public Response upload(String filePath, String key) throws IOException {
        Response res = null;

        try {
            res = this.uploadManager.put(filePath, key, getUpToken());

            System.out.println(res.bodyString());
            System.out.println(res.statusCode);
        } catch (QiniuException e) {
            System.out.println(e);
            Response r = e.response;

            System.out.println(r.toString());

            try {
                System.out.println(r.bodyString());
            } catch (QiniuException qiniuException) {}
        }


        return res;
    }


    public static void main(String[] args) throws IOException { (new QiNiuFileUpUtil()).upload("E:\\zxh\\test.pdf", "test.png"); }
}
